package com.bbg.amyam.web.service.login;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

public class LoginLandingService extends SavedRequestAwareAuthenticationSuccessHandler  {

	@Override
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws ServletException, IOException {
		
		String target = request.getParameter("_uname");
		target=target==null?"default":target;
		
		request.getSession(true).setAttribute("_amyam_unit_name_",target);
		
		super.setAlwaysUseDefaultTargetUrl(true);
		super.setDefaultTargetUrl("/"+target);
		
		super.onAuthenticationSuccess(request, response, authentication);
	}

	
}
